package Day09;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentTest {
    public static void main(String[] args) {
        ArrayList<Student> array = new ArrayList<Student>();
        addStudent(array);
        addStudent(array);
        addStudent(array);
        for (int i = 0; i <array.size() ; i++) {
            Student ss=array.get(i);
//            System.out.println(ss);//直接输出的是地址，除非在类的定义加一个toString
            System.out.println(ss.getName()+","+ss.getAge());
        }
    }

    public static void addStudent(ArrayList<Student> arrayList) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入学生姓名");
        String name = sc.nextLine();
        System.out.println("请输入学生年龄");
        String age = sc.nextLine();
        Student s = new Student();
        s.setName(name);
        s.setAge(age);
        arrayList.add(s);
    }
}
